package com.xinqing.test.LetCode;

import java.util.HashSet;

/**
 * @Author:CHQ
 * @Date:2021/7/21 13:43
 * @Description
 */
public class FindRepeatNumber {
    public static void main(String args[]) {

        int[] nums = {1, 2, 2, 3, 4};
        System.out.println(test(nums));


    }

    public static int test(int[] nums) {
        HashSet<Integer> set = new HashSet<>();

        for (int i = 0; i < nums.length; i++) {
            if (!set.add(nums[i])) {
                return nums[i];
            }
            set.add(nums[i]);
        }
        return -1;
    }
}
